feat: Add Gemini Realtime provider implementing IRealtimeClient/IRealtimeClientSession#256
Open
tarekgh wants to merge 2 commits intogoogleapis:mainfrom
Open
feat: Add Gemini Realtime provider implementing IRealtimeClient/IRealtimeClientSession#256tarekgh wants to merge 2 commits intogoogleapis:mainfrom
tarekgh wants to merge 2 commits intogoogleapis:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
32fa581 to
1d54288
Compare
Author
|
CC @stephentoub |
jeffhandley
reviewed
Mar 19, 2026
1d54288 to
a5345ce
Compare
…timeClientSession
a5345ce to
dd1b649
Compare
- Use SendRealtimeInputAsync for all input types (text, image, audio) to avoid interleaving with SendClientContentAsync which causes WebSocket close - Fix VAD handling: use ActivityStart/ActivityEnd framing when VAD is disabled, AudioStreamEnd when VAD is enabled for push-to-talk - Fix image input: send as Video blob without activity framing, use minimal text trigger in CreateResponse since Gemini treats images as streaming context - Fix function calling: convert MEAI JsonSchema to Google Schema type with proper uppercase type names (STRING, OBJECT, etc.) - Text input auto-triggers model response without framing
dd1b649 to
6121fcf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Gemini Live API provider implementing the
Microsoft.Extensions.AIRealtime abstractions (IRealtimeClient/IRealtimeClientSession), enabling real-time audio, text, and function-calling conversations with Gemini models through the standardized MEAI interface.This PR also updates the repository to depend on the official
Microsoft.Extensions.AI.Abstractions 10.4.1NuGet package (replacing the private10.5.0-devbuilds).What's Included
New Files
GoogleGenAIRealtimeClient.cs—IRealtimeClientimplementation that wraps aGoogle.GenAI.Clientand creates realtime sessions via the Gemini Live API.GoogleGenAIRealtimeSession.cs—IRealtimeClientSessionimplementation that manages the WebSocket connection, audio buffering, message mapping, and function call orchestration.GoogleGenAIRealtimeTest.cs— 118 unit tests covering the full surface area.Modified Files
GoogleGenAIExtensions.cs— AddedAsIRealtimeClient()extension method.Directory.Packages.props— UpdatedMicrosoft.Extensions.AI.Abstractionsfrom10.5.0-dev→10.4.1.Live.cs— Minor adjustment to exposeAsyncSessionfor the realtime provider.packages.lock.jsonfiles regenerated.Features
FunctionInvokingRealtimeSessionmiddleware; tool responses are batched into a singleSendToolResponseAsynccallSemaphoreSlimserializes all WebSocket sends, safe for concurrent middleware + caller usageUsage Example
Key Design Decisions
Tool response batching — The MEAI
FunctionInvokingRealtimeSessionmiddleware sends separateCreateConversationItemper function result. Gemini expects all results in oneSendToolResponseAsynccall. The provider buffers results and flushes them as a single batch whenCreateResponsearrives.TurnComplete suppression after tool responses — After
SendToolResponseAsync, Gemini automatically continues generating. Sendingclient_contentwithturn_complete: truecauses the server to close the WebSocket. The provider tracks this via_lastSendWasToolResponseand skips TurnComplete accordingly.VAD handling — When VAD is disabled (default), the provider wraps audio commits with explicit
ActivityStart/ActivityEndframing. When enabled, the server handles speech boundary detection automatically.Audio buffer cap — Audio appends are capped at 10 MB to prevent unbounded memory growth. Frames exceeding 32 KB are automatically split.
Test Coverage
118 unit tests covering:
BuildLiveConnectConfigmapping (all option combinations)